package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		response.setContentType("text/html;charset=UTF-8");
		if("admin".equals(userName) && "admin".equalsIgnoreCase(password)) {
			request.getSession().setAttribute("role", "admin");
			response.getWriter().append("admin登录成功");
		} else if("user".equals(userName) && "user".equalsIgnoreCase(password)) {
			request.getSession().setAttribute("role", "user");
			response.getWriter().append("user登录成功");
		} else {
			request.getSession().setAttribute("role", null);
			response.getWriter().append("登录失败");
		}
}
}
